package net.qiqbframework.serialization;

public class UnknownSerializedType {

    private final Serializer serializer;
    private final SerializedObject<?> serializedObject;


    public UnknownSerializedType(Serializer serializer, SerializedObject<?> serializedObject) {
        this.serializer = serializer;
        this.serializedObject = serializedObject;
    }


    public <T> boolean supportsFormat(Class<T> desiredFormat) {
        return serializer.getConverter().canConvert(serializedObject.getContentType(), desiredFormat);
    }


    public <T> T readData(Class<T> desiredFormat) {
        return serializer.getConverter().convert(serializedObject, desiredFormat).getData();
    }

    public SerializedType serializedType() {
        return serializedObject.getType();
    }
}
